<?php

namespace Dddxiu\rules;

use Dddxiu\Layer;

/**
 * 电子邮箱
 */
class Email implements Rule
{
    // flag
    const F = 'mail';


    /**
     * @param array $input
     * @param string $field
     * @param Layer $layer
     * @param array $args
     * @return \Closure|bool
     * @throws \Exception
     */
    public static function valid($input, $field, $layer, $args)
    {
        $pass = (filter_var($input[$field], FILTER_VALIDATE_EMAIL) !== false);
        if ($pass) {
            return $layer::next(['type' => Layer::FIELD_TYPE_STR]);
        }
        return false;
    }
}